﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Crm
{
    public partial class Home : Page
    {
        CrmClient.CrmServiceClient client = new CrmClient.CrmServiceClient();
        public Home()
        {
            InitializeComponent();
            this.Loaded += Home_Loaded;
            client.ZiyaretEdileceklerCompleted += client_ZiyaretEdileceklerCompleted;
            client.TelefonlaGorusuleceklerCompleted += client_TelefonlaGorusuleceklerCompleted;
        }

        void client_TelefonlaGorusuleceklerCompleted(object sender, CrmClient.TelefonlaGorusuleceklerCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                grdTelefon.DataSource = e.Result;
                grdTelefon.Columns["BaslangicTarihi"].VisibleIndex = 0;
                grdTelefon.Columns["FirmaTipi"].VisibleIndex = 1;
                grdTelefon.Columns["FirmaKodu"].VisibleIndex = 2;
                grdTelefon.Columns["FirmaUnvani"].VisibleIndex = 3;
                grdTelefon.Columns["Yer"].VisibleIndex = 4;
                grdTelefon.Columns["Konu"].VisibleIndex = 5;
                grdTelefon.Columns["ID"].Visible = false;
                grdTelefon.ColumnsAutoWidth = true;
            }
        }

        void client_ZiyaretEdileceklerCompleted(object sender, CrmClient.ZiyaretEdileceklerCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                grdZiyaret.DataSource = e.Result;
                grdZiyaret.Columns["BaslangicTarihi"].VisibleIndex = 0;
                grdZiyaret.Columns["FirmaTipi"].VisibleIndex = 1;
                grdZiyaret.Columns["FirmaKodu"].VisibleIndex = 2;
                grdZiyaret.Columns["FirmaUnvani"].VisibleIndex = 3;
                grdZiyaret.Columns["Yer"].VisibleIndex = 4;
                grdZiyaret.Columns["Konu"].VisibleIndex = 5;
                grdZiyaret.Columns["ID"].Visible = false;
                grdZiyaret.ColumnsAutoWidth = true;
            }
        }

        void Home_Loaded(object sender, RoutedEventArgs e)
        {
            client.TelefonlaGorusuleceklerAsync(0);
            client.ZiyaretEdileceklerAsync(0);
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
    }
}